<template>
  <a-radio-group
    v-if="tagType=='radio'"
    @change="handleInput"
    :value="getValueSting"
    :disabled="disabled"
  >
    <a-radio
      v-for="(item, key) in dictOptions"
      :key="key"
      :value="item.value"
    >
      {{ item.text }}
    </a-radio>
  </a-radio-group>

  <a-select
    v-else-if="tagType=='select'"
    :get-popup-container="(target) => target.parentNode"
    :placeholder="placeholder"
    :disabled="disabled"
    :value="getValueSting"
    @change="handleInput"
  >
    <a-select-option :value="undefined">
      请选择
    </a-select-option>
    <a-select-option
      v-for="(item, key) in dictOptions"
      :key="key"
      :value="item.codeValue"
    >
      <span
        style="display: inline-block;width: 100%"
        :title=" item.text  || item.label|| item.textValue"
      >
        {{ item.text || item.label|| item.textValue }}
      </span>
    </a-select-option>
  </a-select>
</template>

<script>
//引入manage.js文件里面的getAction请求方法
import { getAction  } from '@/api/manage'

export default {
  name: 'JDictSelectTag',
  props: {
    dictCode: String,
    placeholder: String,
    triggerChange: Boolean,
    disabled: Boolean,
    value: [String, Number],
    type: String
  },
  data () {
    return {
      dictOptions: [],
      tagType: ''
    }
  },
  watch: {
    dictCode: {
      immediate: true,
      handler () {
        this.initDictData()
      }
    }
  },
  created () {
    console.log(this.dictCode);
    if (!this.type || this.type === 'list') {
      this.tagType = 'select'
    } else {
      this.tagType = this.type
    }
    // 获取字典数据
    // this.initDictData();
  },
  computed: {
    getValueSting () {
      return this.value ? this.value.toString() : null
    }
  },
  methods: {
    initDictData () {
      // 根据字典Code, 初始化字典数组

      //获取查询条件接口数据请求
      getAction('/mes-manufacture/mfProcess/getFilter', {}).then((res) => {
        if (res.success) {
          console.log(res.data);
          if(this.dictCode=='mes_filed_type'){
            this.dictOptions = res.data.workrooms
          }else if(this.dictCode=='mes_filed_pro'){
            this.dictOptions = res.data.processTwos
          }
          
        }
      })
    },
    handleInput (e) {
      let val
      if (this.tagType == 'radio') {
        val = e.target.value
      } else {
        val = e
      }
      console.log(val)
      if (this.triggerChange) {
        this.$emit('change', val)
      } else {
        this.$emit('input', val)
      }
    },
    setCurrentDictOptions (dictOptions) {
      this.dictOptions = dictOptions
    },
    getCurrentDictOptions () {
      return this.dictOptions
    }
  }
}
</script>

<style scoped>
</style>
